package com.jr.controller;

import com.jr.entry.PersonalInformation;
import com.jr.entry.User;
import com.jr.service.PersonalInformationService;
import com.jr.service.UserService;
import com.jr.service.impl.PersonalInformationServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/personalInformation/")
public class PersonalInformationController {
    @Autowired
    private PersonalInformationService pis;
    @Autowired
    private UserService userService;

    @RequestMapping("insert")
    public ResponseEntity<Boolean> insert(PersonalInformation pi,User user) {
        boolean b1 = pis.insertInformation(pi) > 0 ? true : false;

        User user1 = userService.login(user);
        boolean b2 = false;
        if(user1!=null) {
            b2=true;
        }
        return ResponseEntity.ok(b1&&b2);
    }

    @RequestMapping("selectInformation")
    public PersonalInformation select(User user) {
        PersonalInformation p = pis.selectInformation(user);
        return p;
    }

    @RequestMapping("update")
    public ResponseEntity<Boolean> update(PersonalInformation pi) {
        boolean b = pis.updateInformation(pi);
        return ResponseEntity.ok(b);
    }

    @RequestMapping("selectUser")
    public User selectUser(User user) {
        User u = pis.selectUserInformation(user);
        System.out.println(u);
        return u;
    }

}
